<?php

namespace app\common\validate\shop;

use app\common\validate\BaseValidate;

class Category extends BaseValidate
{
    /**
     * 验证规则
     */
    protected $rule = [
        'name|分类名称' => 'require|checkName|length:1,30',
        'image|图标'   => 'require',
        'is_nav|是否为导航' => 'require'
    ];

    /**
     * 提示消息
     */
    protected $message = [
    ];

    protected function checkName($value, $rule='', $data='', $field='')
    {
        $is_nav = $data['is_nav'];
        $topid = $data['topid'];
        if ($is_nav == 1 && $topid != 0) {
            return '只有一级类目能设置在导航栏';
        }

        if ($is_nav == 1 && $data['is_hot'] == 1) {
            return '导航栏和热门同时只能设计一个';
        }
        return true;

    }
    /**
     * 验证场景
     */
    protected $scene = [
        'add'  => [],
        'edit' => [],
    ];
    
}
